﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Resn.WhuPub.BIL;
using Resn.WhuPub.BLL;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// UpdateCategoryWindow.xaml 的交互逻辑
        /// </summary>
        public partial class UpdateCategoryPage : Page
        {
                private readonly GlobalManager gm = GlobalManager.Instance;

                public UpdateCategoryPage()
                {
                        InitializeComponent();
                }

                private void Page_Loaded(object sender, RoutedEventArgs e)
                {
                        gm.CategoryName = gm.Category.Name;
                        gm.CategoryCode = gm.Category.Code;

                        LayoutRoot.DataContext = gm;
                }

                private void AcceptButton_Click(object sender, RoutedEventArgs e)
                {
                        if (String.IsNullOrEmpty(gm.CategoryName))
                        {
                                MessageBox.Show("专业名称不能为空");
                                return;
                        }

                        if (String.IsNullOrEmpty(gm.CategoryCode))
                        {
                                MessageBox.Show("专业代码不能为空");
                                return;
                        }

                        try
                        {
                                gm.Category.Name = gm.CategoryName;
                                gm.Category.Code = gm.CategoryCode;
                                gm.Category.Update();
                        }
                        catch (Exception ex)
                        {
                                MessageBox.Show(ex.Message);
                                return;
                        }

                        finally
                        {
                        }

                        NavigationService.GoBack();
                }

                
        }
}